﻿using System;

namespace Testing.Helpers.Converters
{
    /// <summary>
    /// Converter from string to DateTime?.
    /// </summary>
    public static class StringToDateTimeConverter
    {
        /// <summary>
        /// Convert from string to DateTime?.
        /// </summary>
        /// <param name="dateTimeStr">Тhe text representation of the date.</param>
        /// <param name="provider">Format provider.</param>
        /// <returns>DateTime?</returns>
        public static DateTime? Convert(string dateTimeStr, IFormatProvider provider)
        {
            return (dateTimeStr.Length == 0) 
                ? null
                : new DateTime?(DateTime.Parse(dateTimeStr, provider));
        }
    }
}
